package ai.people.netmon.telegram.controller;

import ai.people.netmon.framework.domain.telegram.entity.Users;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.ResponseResult;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.telegram.domain.request.channels.UsersRequest;
import ai.people.netmon.telegram.service.ManageUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 隐匿网络信源探测系统-用户
 *
 * @author yuanqinglong
 * @date 2022/1/7 16:29
 */
@RestController
@Validated
@RequestMapping("/manage/user")
public class ManageUserController {


    @Autowired
    private ManageUserService manageUserServiceImpl;

    /**
     * 分页查询用户
     *
     * @param usersConditions 用户环境
     * @return {@link Result}<{@link PageResponse}<{@link Users}>>
     */
    @GetMapping
    public Result<PageResponse<Users>> selectByPage(@RequestBody UsersRequest usersConditions){
        PageResponse<Users> usersPageResponse = manageUserServiceImpl.selectUserPage(usersConditions);
        return ResultUtil.success(usersPageResponse);
    }


    /**
     * 获取用户
     *
     * @param userId 用户id
     * @return {@link Result}<{@link Users}>
     */
    @GetMapping("/{userId}")
    public Result<Users> getUSer(@PathVariable Long userId){
        Users users = manageUserServiceImpl.selectById(userId);
        return ResultUtil.success(users);
    }


    /**
     * 添加用户
     *
     * @param users 用户
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> addUser(@Valid @RequestBody Users users){
        manageUserServiceImpl.addUser(users);
        return ResultUtil.success();
    }


    /**
     * 更新用户
     *
     * @param users 用户
     * @return {@link ResponseResult}
     */
    @PutMapping
    public Result<?> updateUser(@RequestBody Users users){
        manageUserServiceImpl.updateUserById(users);
        return ResultUtil.success();
    }


    /**
     * 删除用户
     *
     * @param userId 用户id
     * @return {@link ResponseResult}
     */
    @DeleteMapping("/{userId}")
    public Result<?> deleteUser(@PathVariable Long userId){
        manageUserServiceImpl.deleteUserById(userId);
        return ResultUtil.success();
    }


    /**
     * 标注用户
     *
     * @param userId 用户id
     * @return {@link ResponseResult}
     */
    // TODO: 2022/1/7 标注
    public Result<?> labelUser(Long userId){


        return ResultUtil.success();
    }



}
